$(->
  queries = {}
  queries.t = 'weibo'
  $.each document.location.search.substr(1).split('&'), (c,q)->
    i = q.split('=')
    if i[1]
      queries[i[0].toString()] = i[1].toString()

  keep_access = (sids)->
    $.ajax
      url: "/sns/keep_access"
      type: "PUT"
      data:
        ids:  sids
        t: queries.t
      success: (retval) =>
        msg = retval.msg
        $s.alert(msg.type, msg.content)
        console.log "success keep_access weibos"
      error: (retval) ->
        msg = retval.msg
        $s.alert(msg.type, msg.content)

  stop = (sids)->
    $.ajax
      url: "/sns/stop"
      type: "DELETE"
      data:
        ids:  sids
      success: (retval) =>
        msg = retval.msg
        $s.alert(msg.type, msg.content)
        console.log "success stop weibos"
      error: (retval) ->
        msg = retval.msg
        $s.alert(msg.type, msg.content)

  revive = (sids)->
    $.ajax
      url: "/sns/revive"
      type: "PUT"
      data:
        ids:  sids
      success: (retval) =>
        msg = retval.msg
        $s.alert(msg.type, msg.content)
        console.log "success revive weibos"
      error: (retval) ->
        msg = retval.msg
        $s.alert(msg.type, msg.content)

  destroy = (sids)->
    $.ajax
      url: "/sns/destroy"
      type: "DELETE"
      data:
        ids:  sids
        t: queries.t
      success: (retval) =>
        msg = retval.msg
        $s.alert(msg.type, msg.content)
        console.log "success delete weibos"
      error: (retval) ->
        msg = retval.msg
        $s.alert(msg.type, msg.content)

  auto_access = (sids) ->
    $.ajax
      url: "/sns/auto_access"
      type: "PUT"
      data:
        ids:  sids
        t: queries.t
      success: (retval) =>
        msg = retval.msg
        $s.alert(msg.type, msg.content)
      error: (retval) ->
        msg = retval.msg
        $s.alert(msg.type, msg.content)


  $('.keat-btn').click ->
    $s.alert_hide
    sids = [$(this).closest('tr').attr('id')]
    keep_access(sids)

  $('.stop-btn').click ->
    $s.alert_hide
    sids = [$(this).closest('tr').attr('id')]
    stop(sids)

  $('.revive-btn').click ->
    $s.alert_hide
    sids = [$(this).closest('tr').attr('id')]
    revive(sids)

  $('.delete-btn').click ->
    $s.alert_hide
    sids = [$(this).closest('tr').attr('id')]
    destroy(sids)

  $('.autoacs-btn').click ->
    $s.alert_hide
    auto_access()
)